<!-- 首页子路由组件-elementUI的Layout布局 -->
<template>
  <div>
    <div class="container-fluid">
      <el-row class="curve-pie" :gutter="10">
        <el-col :sm="18" :xs="18">
          <div class="gragh_pannel" id="curve_show"></div>
        </el-col>
        <el-col :sm="6" :xs="6">
          <div class="gragh_pannel" id="pie_show">
            <div slot="header" class="clearfix">
              <span><i class="el-icon-document"></i> 联系方式</span>
            </div>
            <div class="ItemList">
              <span class="left">
                <img src="https://imgs.bwmelon.com/20190506153933.png" alt="">
              </span>
              <div>
                <p>QQ</p>
                <p>2423902761</p>
              </div>
            </div>
            <div class="ItemList">
              <span class="left">
                <img src="https://imgs.bwmelon.com/20190506153935.png" alt="">
              </span>
              <div>
                <p>邮箱</p>
                <p>qwe6846151@163.com</p>
              </div>
            </div>
            <div class="ItemList">
              <span class="left">
                <img src="https://imgs.bwmelon.com/20190506153934.png" alt="">
              </span>
              <div>
                <p>网易云音乐</p>
                <p>你的网易云账号</p>
              </div>
            </div>
            <div class="ItemList">
              <span class="left">
                <img src="../../assets/images/baby.jpg" alt="" style="border-radius: 50%;">
                <!-- <i class="el-icon-apple" style="font-size: 40px;"></i> -->
              </span>
              <div>
                <p>微信</p>
                <p>qwe6846151</p>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="container-fluid">
      <div class="column_pannel" id="column_show"></div>
    </div>
  </div>
</template>

<script>
// 引入图表管理插件
// echarts内部用的是命名导出 export const 变量名 多个
// 正常情况下:{变量名,变量名}
// 但是我想全部导出?如下:
import * as echarts from 'echarts'
// 基于准备好的dom，初始化echarts实例(先执行js文件,发现元素不存在)
// const myChart = echarts.init(document.getElementById('curve_show'))
export default {
  name: 'my-home',
  mounted() {
    // 初始化面积图-调用函数
    this.setCurveChartFn()
    // 初始化底部柱形图-调用函数
    this.initCurveFn()
  },
  methods: {
    // 初始化面积图
    // 设置面积图
    setCurveChartFn() {
      // 基于准备好的dom，初始化echarts实例
      const curveChart = echarts.init(document.getElementById('curve_show'))
      // 绘制面积图表
      // 数据源(模拟后台返回的数据)
      const aListAll = [
        { count: 36, date: '2023-01-01' },
        { count: 52, date: '2023-01-01' },
        { count: 78, date: '2023-01-01' },
        { count: 85, date: '2023-01-01' },
        { count: 65, date: '2023-01-01' },
        { count: 72, date: '2023-01-01' },
        { count: 88, date: '2023-01-01' },
        { count: 64, date: '2023-01-02' },
        { count: 72, date: '2023-01-02' },
        { count: 90, date: '2023-01-02' },
        { count: 96, date: '2023-01-02' },
        { count: 100, date: '2023-01-05' },
        { count: 102, date: '2023-01-05' },
        { count: 110, date: '2023-01-05' },
        { count: 123, date: '2023-01-05' },
        { count: 100, date: '2023-01-06' },
        { count: 132, date: '2023-01-06' },
        { count: 146, date: '2023-01-06' },
        { count: 200, date: '2023-01-06' },
        { count: 180, date: '2023-01-06' },
        { count: 163, date: '2023-01-06' },
        { count: 110, date: '2023-01-06' },
        { count: 80, date: '2023-01-12' },
        { count: 82, date: '2023-01-12' },
        { count: 70, date: '2023-01-12' },
        { count: 65, date: '2023-01-12' },
        { count: 54, date: '2023-01-12' },
        { count: 40, date: '2023-01-12' },
        { count: 45, date: '2023-01-12' },
        { count: 38, date: '2023-01-12' }
      ]

      // 但是图标要求直接给数字的值, 所以要把对象的值取出来形成2个只有值的数组
      const aCount = []
      const aDate = []

      for (let i = 0; i < aListAll.length; i++) {
        aCount.push(aListAll[i].count)
        aDate.push(aListAll[i].date)
      }

      // 面积图的echarts配置项(参考文档复制)
      const chartopt = {
        title: {
          text: '月新增文章数', // 标题
          left: 'center', // 位置居中
          top: '10' // 标题距离容器顶部px
        },
        tooltip: {
          // 提示框组件
          trigger: 'axis' // 坐标轴触发(鼠标放在坐标轴就能出提示框)
        },
        legend: {
          // 图例组件(每种颜色的意思)
          data: ['新增文章'], // 图例文字解释(要和series里name对应)
          top: '40' // 距离容器顶部px
        },
        toolbox: {
          // 工具栏
          show: true, // 要显示
          feature: {
            // 各工具配置项
            mark: { show: true }, // 辅助线开关
            dataView: { show: true, readOnly: false }, // 数据视图工具，可以展现当前图表所用的数据，编辑后可以动态更新。
            magicType: { show: true, type: ['line', 'bar'] }, // 动态类型切换
            restore: { show: true }, // 配置项还原
            saveAsImage: { show: true } // 点击保存下载图片
          }
        },
        xAxis: [
          // 水平轴显示
          {
            name: '日',
            type: 'category',
            boundaryGap: false, // 坐标轴两边留白策略 (不留白)
            data: aDate // 水平轴上的数字数据 (时间)
          }
        ],
        yAxis: [
          // 垂直轴显示
          {
            name: '月新增文章数',
            type: 'value' // 以series里的data值做划分段
          }
        ],
        series: [
          // 系列(控制图表类型和数据)
          {
            name: '新增文章',
            type: 'line', // 折线图
            smooth: true, // 是否平滑视觉引导线，默认不平滑，可以设置成 true 平滑显示
            areaStyle: { type: 'default' }, // 区域填充样式。设置后显示成区域面积图。
            itemStyle: { color: '#f80', lineStyle: { color: '#f80' } }, // 折线拐点标志的样式。
            data: aCount // 真正数据源(用下标和x轴数组对应)
          }
        ],
        grid: {
          // 直角坐标系内绘图网格
          show: true,
          x: 50, // grid 组件离容器偏移量, 左侧
          x2: 50, // 右侧
          y: 80, // 上
          height: 220 // 高度
        }
      }

      curveChart.setOption(chartopt)
    },
    initCurveFn() {
      const oColumn = echarts.init(document.getElementById('column_show'))
      const oColumnopt = {
        title: {
          text: '文章访问量',
          left: 'center',
          top: '10'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['HTMl/CSS', 'JavaScript', 'Jquery', 'Ajax/Promise/Axios', 'Node.js', 'Vue全家桶'],
          top: '40'
        },
        toolbox: {
          show: true,
          feature: {
            mark: { show: true },
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        xAxis: [
          {
            type: 'category',
            data: ['1月', '2月', '3月', '4月', '5月']
          }
        ],
        yAxis: [
          {
            name: '访问量',
            type: 'value'
          }
        ],
        series: [
          {
            name: 'HTMl/CSS',
            type: 'bar',
            barWidth: 20,
            areaStyle: { type: 'default' },
            itemStyle: {
              color: '#fd956a'
            },
            data: [800, 708, 920, 1090, 1200]
          },
          {
            name: 'JavaScript',
            type: 'bar',
            barWidth: 20,
            areaStyle: { type: 'default' },
            itemStyle: {
              color: '#ccd9ff'
            },
            data: [400, 468, 520, 690, 800]
          },
          {
            name: 'Jquery',
            type: 'bar',
            barWidth: 20,
            areaStyle: { type: 'default' },
            itemStyle: {
              color: '#ffb3bb'
            },
            data: [500, 668, 620, 790, 900]
          },
          {
            name: 'Ajax/Promise/Axios',
            type: 'bar',
            barWidth: 20,
            areaStyle: { type: 'default' },
            itemStyle: {
              color: '#dcb8ff'
            },
            data: [600, 708, 820, 890, 1200]
          },
          {
            name: 'Node.js',
            type: 'bar',
            barWidth: 20,
            areaStyle: { type: 'default' },
            itemStyle: {
              color: '#99eeff'
            },
            data: [400, 508, 720, 850, 1000]
          },
          {
            name: 'Vue全家桶',
            type: 'bar',
            barWidth: 20,
            areaStyle: { type: 'default' },
            itemStyle: {
              color: '#b4adff'
            },
            data: [600, 708, 820, 900, 1200]
          }
        ],
        grid: {
          show: true,
          x: 50,
          x2: 30,
          y: 80,
          height: 260
        },
        dataZoom: [
          // 给x轴设置滚动条
          {
            start: 0, // 默认为0
            end: 100 - 1000 / 31, // 默认为100
            type: 'slider',
            show: true,
            xAxisIndex: [0],
            handleSize: 0, // 滑动条的 左右2个滑动条的大小
            height: 8, // 组件高度
            left: 45, // 左边的距离
            right: 50, // 右边的距离
            bottom: 26, // 右边的距离
            handleColor: '#ddd', // h滑动图标的颜色
            handleStyle: {
              borderColor: '#cacaca',
              borderWidth: '1',
              shadowBlur: 2,
              background: '#ddd',
              shadowColor: '#ddd'
            }
          }
        ]
      }
      oColumn.setOption(oColumnopt)
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .gragh_pannel {
  height: 350px;
  border: 1px solid #e7e7e9;
  background-color: rgba(242, 242, 242, 0.6);
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  border-radius: 4px;
}
/deep/ .column_pannel {
  margin-top: 10px;
  height: 400px;
  border: 1px solid #e7e7e9;
  background-color: rgba(242, 242, 242, 0.6);
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  border-radius: 4px;
}
#pie_show {
  padding: 10px;
  background-color: rgba(242, 242, 242, 0.5);
  span {
    font-size: 16px;
  }
  i {
    margin-right: 8px;
    font-size: 19px;
  }
  .ItemList {
    margin-top: 5px;
    padding: 0.8rem 0.5rem;
    color: #555;
    border-bottom: 1px solid #ccc;
    transition: all 0.6s;
    font-size: 13px;
    display: flex;
    // justify-content: space-between;
    align-items: center;
    span {
      font-size: 14px;
      color: black;
      font-weight: bold;
      white-space: nowrap;
    }
    img {
      width: 40px;
      margin-right: 10px;
      transition: all 1s;
    }
    .left {
      img:hover {
        transform: rotate(360deg);
      }
    }
    p {
      font-size: 16px;
    }
  }
  .ItemList:last-child {
    border-bottom: none;
  }
}
</style>
